package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.entity.Reservation;
import com.zzyl.vo.ReservationCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Mapper
public interface CustomerReservationMapper {
    /**
     * 查询取消预约次数
     */
    @Select("select count(id) from reservation where status = 2 group by id")
    Integer searchCount();

    /**
     * 新增预约数据
     * @param reservation
     */
    void addInfo(Reservation reservation);


    /**
     * 分页查询预约
     * @param status
     * @return
     */
    Page<Reservation> getById(Integer status);

    /**
     * 查询剩余预约次数
     * @param
     * @param
     * @return
     */
    List<ReservationCountVo> getRemindCount(Date startTime, Date endTime);

    /**
     * 取消预约
     */
    void cancel(Long id);

    /**
     * 定时任务
     */
    @Update("update reservation set status = 3 where now() between time and DATE_ADD(time,INTERVAL 1 HOUR) and status != 1 and status != 2")
    void setStatus();

    Integer canceCount(LocalDateTime startTime, LocalDateTime endTime, Long userId);

    void update(Reservation reservation);
}
